CLASS zcl_feishu_job_001 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    DATA gv_token TYPE string.
    INTERFACES if_apj_dt_exec_object .
    INTERFACES if_apj_rt_exec_object .

  PROTECTED SECTION.
  PRIVATE SECTION.

    CONSTANTS app_secret TYPE string VALUE 'rpSQut0hifypNSLGvWqxJdZKM64VD2C4'.
    CONSTANTS app_id TYPE string VALUE 'cli_a7bb77ce43f8900c'.

    " Approval Code
    CONSTANTS _p1 TYPE string VALUE '差旅' ##NO_TEXT.
    CONSTANTS approval_code_01 TYPE string VALUE '138BA444-D18C-4580-B04B-315D0868F270' ##NO_TEXT.
    CONSTANTS _p2 TYPE string VALUE '招待' ##NO_TEXT.


ENDCLASS.



CLASS zcl_feishu_job_001 IMPLEMENTATION.


  METHOD if_apj_dt_exec_object~get_parameters.

    " the supported selection parameters
    et_parameter_def = VALUE #(
   (  selname = 'P_MOD1'  kind = 'P' radio_group_ind = 'X' datatype = 'C' length = 1 param_text = _p1  changeable_ind  = 'X' radio_group_id = 'G1' )
   (  selname = 'P_MOD2'  kind = if_apj_dt_exec_object=>parameter radio_group_ind = 'X' datatype = 'C' length = 1 param_text = _p2 changeable_ind  = 'X' radio_group_id = 'G1' )
   (  selname = 'P_MOD3'  kind = if_apj_dt_exec_object=>parameter radio_group_ind = 'X' datatype = 'C' length = 1 param_text = '员工借款' changeable_ind  = 'X' radio_group_id = 'G1' )
   (  selname = 'P_MOD4'  kind = if_apj_dt_exec_object=>parameter radio_group_ind = 'X' datatype = 'C' length = 1 param_text = '日常报销' changeable_ind  = 'X'  radio_group_id = 'G1' )
   (  selname = 'P_MOD5'  kind = if_apj_dt_exec_object=>parameter radio_group_ind = 'X' datatype = 'C' length = 1 param_text = '付款' changeable_ind  = 'X'  radio_group_id = 'G1')
     ).

    " Default paramrters values
    et_parameter_val = VALUE #(
     (  selname = 'P_MOD1'  kind = if_apj_dt_exec_object=>parameter  sign = 'I' option = 'EQ' low = 'X' )
    ).
  ENDMETHOD.


  METHOD if_apj_rt_exec_object~execute.
    DATA: p_mod1,p_mod2,p_mod3,p_mod4,p_mod5 TYPE abap_bool.

    LOOP AT it_parameters INTO DATA(ls_paramenters).
      CASE ls_paramenters-selname.
        WHEN 'P_MOD1' .
          p_mod1 = ls_paramenters-low.
        WHEN 'P_MOD2' .
          p_mod2 = ls_paramenters-low.
        WHEN 'P_MOD3' .
          p_mod3 = ls_paramenters-low.
        WHEN 'P_MOD4' .
          p_mod4 = ls_paramenters-low.
        WHEN 'P_MOD5' .
          p_mod5 = ls_paramenters-low.
      ENDCASE.
    ENDLOOP.


    DATA ls_appid TYPE t_appid.
    CLEAR ls_appid.

    ls_appid-app_id =  app_id.
    ls_appid-app_secret = app_secret.

    DATA fs_interface TYPE REF TO lcl_fs_interface.

    fs_interface = NEW #( ).

    " 1、 获取token
    gv_token  =  fs_interface->get_token( ls_appid ).
    IF gv_token IS NOT INITIAL.

      " 2、 获取INSTANCES
      CASE abap_true.
        WHEN p_mod1.
          DATA(ls_taks) =  fs_interface->get_tasks( iv_token = gv_token  iv_approval_code = approval_code_01 ).


          " TODO 3、获取实例信息
          " TODO 4、EML 凭证录入

          " TODO 5、接口调用日志记录
        WHEN p_mod2.
        WHEN p_mod3.
        WHEN p_mod4.
        WHEN p_mod5.

      ENDCASE.
    ENDIF.

  ENDMETHOD.
ENDCLASS.
